<?php


header("Content-type: application/json; charset=utf-8");
header("Access-Control-Allow-Origin: *");

//获取设备信息


if(isset($_POST["host"])&&$_POST["community"]){




$host=$_POST["host"];

$community=$_POST["community"];

function check($host,$community){




  $flag=true;
  $sysDescr = @str_replace("STRING:","",snmpget("$host","$community","system.sysDescr.0",200));


  if($sysDescr){
    $flag=true;
  }else{
    $flag=false;
  }

return $flag;

}

function get_systeminfo($host,$community){

  $sysDescr = @str_replace("STRING:","",snmpget("$host","$community","system.sysDescr.0"));

  $sysObjectID = @str_replace("OID:","",snmpget("$host","$community","system.sysObjectID.0"));
  $sysUpTime = @str_replace("Timeticks:","",snmpget("$host","$community","system.sysUpTime.0"));
  $sysContact = @str_replace("STRING:","",snmpget("$host","$community","sysContact.0"));
  $sysName = @str_replace("STRING:","",snmpget("$host","$community","system.sysName.0"));
  $sysLocation = @str_replace("STRING:","",snmpget("$host","$community","system.sysLocation.0"));
  $sysServices = @str_replace("INTEGER:","",snmpget("$host","$community","system.sysServices.0"));

  $sysarray=array("sysDescr"=>trim($sysDescr),"sysObjectID"=>trim($sysObjectID),"sysUpTime"=>trim($sysUpTime),"sysContact"=>trim($sysContact),"sysName"=>trim($sysName),"sysLocation"=>trim($sysLocation),"sysServices"=>trim($sysServices));

  return $sysarray;

}

$tar1=array();
$main_arr = array("设备信息"=>$tar1);

$flag=check("$host","$community");



$sc=true;
if($flag){
$info=get_systeminfo("$host","$community");
$sc=true;
}else{
  $info=array();
  $sc=false;
}

array_push($main_arr["设备信息"],$info);

$arr = array("success" => $sc,"info"=>$main_arr );
echo json_encode($arr);

}
 ?>
